import type { OrderDetailResult, OrderListParams, OrderListResult, OrderLogisticResult, OrderParams, OrderResult } from "@/types/order"
import { http } from "@/utils/http"

export const useOrderApi = () => {
    return {
        /**
         * 订单信息--立即购买
         * @returns 
         */
        getOrderNow: (data: {
            skuId: string,
            count: string,
            addressId?: string
        }) => {
            return http<OrderResult>({
                method: 'GET',
                url: '/member/order/pre/now',
                data
            })
        },
        /**
         * 订单信息--购物车进去
         */
        getOrderPre: () => {
            return http<OrderResult>({
                method: 'GET',
                url: '/member/order/pre'
            })
        },
        /**
         * 提交订单
         */
        addOrder: (data: OrderParams) => {
            return http<{ id: string }>({
                method: 'POST',
                url: '/member/order',
                data,
            })
        },
        /**
         * 获取订单详情
         */
        getOrderDetail: (id: string) => {
            return http<OrderDetailResult>({
                method: 'GET',
                url: `/member/order/${id}`
            })
        },
        /**
         * 订单信息--再次购买
         */
        getOrderRe: (id: string) => {
            return http<OrderResult>({
                method: 'GET',
                url: `/member/order/repurchase/${id}`
            })
        },
        /**
         * 模拟发货
         */
        mockConsign: (id: string) => {
            return http<{ msg: string }>({
                method: 'GET',
                url: `/member/order/consignment/${id}`
            })
        },
        /**
         * 确定收货
         */
        receiptOrder: (id: string) => {
            return http<OrderDetailResult>({
                method: 'PUT',
                url: `/member/order/${id}/receipt`
            })
        },
        /**
         * 取消订单
         */
        cancelOrder: (id: string, data: { cancelReason: string }) => {
            return http<OrderDetailResult>({
                method: 'PUT',
                url: `/member/order/${id}/cancel`,
                data
            })
        },
        /**
         * 获取订单物流
         */
        getOrderLogistics: (id: string) => {
            return http<OrderLogisticResult>({
                method: 'GET',
                url: `/member/order/${id}/logistics`
            })
        },
        /**
         * 删除订单
         */
        deleteOrder: (data:{ids:string[]}) => {
            return http<{msg:string}>({
                method: 'DELETE',
                url: `/member/order`,
                data
            })
        },
        /**
         * 获取订单列表
         */
        getOrderList: (data?:OrderListParams) => {
            return http<OrderListResult>({
                method: 'GET',
                url: `/member/order`,
                data
            })
        }
    }
}